/**
 * zmn文章模块-文章编辑
 * 文件命名格式：zmn.模块.表/功能.jas
 * @author duanzuocai
 * @since 2018/11/12
 */
layui.define(['form', 'layedit', 'laydate'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;

    form.render(null, "zmn-module-form");

    // 自定义验证规则
    form.verify({
        title: function(value){
            if(value.length < 2){ return "分类名称不能少于2个字符"; };
        },
        sort: function(value){
            if (!/^[0-9]+$/.test(value)) {
                return "排序值只能是正整数";
            }
        }
    });

    // 提交
    form.on('submit(zmn-module-form-submit)', function(obj){
        var openId = layer.open({type: 3});
        var data = obj.field;
        var url = "/mc/module/addEdit.action";

        $.ajax({
            async: false,
            type: "POST", url: url,
            contentType: "application/json", dataType: "json", data: JSON.stringify(data),
            success:function(json) {
                layer.close(openId);
                layer.msg(json.message);
                if(json.status == 200 && json.id > 0) {
                    zmnPage.direct("/mc/module/detail.action?moduleId=" + json.id, 1500);
                }
            },
            error:function(XMLHttpRequest, textStatus, errorThrown){}
        })
        return false;
    });

    //对外暴露的接口
    exports('art_module_detail', {});
});